import greenfoot.*;  
import java.awt.Color;

/**
 * GameMap show a mappview of all levels
 * extends MiniGame to allow access to GameState information from MiniGame
 * 
 * @author Jasper Jans
 *
 */
public class GameMap extends MiniGame
{

    // The pins on the map where the levels are played
    private GameMapPointer pointer1;
    private GameMapPointer pointer2;
    private GameMapPointer pointer3; 
    private GameMapPointer pointer4;
    
    // The water actor flooding Rotterdam
    private Flood flood;
    
    /*
     * Contructor for the GameMap
     * @startNewGame set to true if this initiates a completely new game
     */
    public GameMap(boolean startNewGame)
    {    

        super(240, 0);
        
        flood = new Flood(this);
        addObject(flood,400,300);
               
        if(startNewGame)
        {
            startNewGame();
            flood.playAnimation(false); // Show flooding of rotterdam
            
        }else
        {   
            if(super.getNextUnCompletedLevel() > 0) // next level is found, if not the game is completed
            {
                flood.setTransparentFlood(); 
                showPointers();
     

            }else
            {
                flood.playAnimation(true);  // Show reverted flood of rottedam when game is finished
            }
            
           
        }
        
        

    }
    
    public void act()
    {
        String key = Greenfoot.getKey();
        
        if(key == "enter")
        {
            if(getGameStatus() == GameStatus.GAMEOVER)
            {
                Greenfoot.setWorld(new TitleScreen());
            }else{
              
                switch(super.getNextUnCompletedLevel())
                {
                    case 0:
                        flood.playAnimation(true);
                        break;
                    case 1: 
                        Greenfoot.setWorld(new Office());
                        break;
                    case 2:
                        Greenfoot.setWorld(new RescueBoats());
                        break;
                    case 3:
                        Greenfoot.setWorld(new SandBags());
                        break;
                    case 4:
                        Greenfoot.setWorld(new PipeLines());
                        break;
                }
            }
                   
                
        }
    }
    
    /*
     * Completes game, yihaaaa, play annoying sound and set game completed labels
     */
    public void endGame()
    {
        GreenfootSound victory = new GreenfootSound("victory.mp3");
        victory.setVolume(50);
        victory.play();
        
        Label theEnd = new Label(this, 20, 500);
        theEnd.setForeColor(Color.BLUE);
        theEnd.setText("Rotterdam is gered!", 50);
        
        Label score = new Label(this, 50, 550);
        score.setForeColor(Color.BLUE);
        score.setText("Jouw score : "  +  Integer.toString(getScore()), 40);
        
        super.gameEnd();    // call game end in minigame
        
    }
    
    /*
     * Adds pointers on map where levels exist
     */
    public void showPointers()
    {
        
        // Instantiate pointers with level number and levelIsCompleted boolean (to set different style pointer)
        pointer1 = new GameMapPointer(1, levelIsCompleted(1));
        pointer2 = new GameMapPointer(2, levelIsCompleted(2));
        pointer3 = new GameMapPointer(3, levelIsCompleted(3));
        pointer4 = new GameMapPointer(4, levelIsCompleted(4));
        
        addObject(pointer1, 75, 400);
        addObject(pointer2, 450, 75);
        addObject(pointer3, 570, 500);
        addObject(pointer4, 350, 400);
                    
        if(super.getNextUnCompletedLevel() > 0)
        {
            Label next = new Label(this, 20, 550);
            next.setForeColor(Color.BLUE);
            next.setText("Druk op enter om het volgende level te starten", 20);
        }
    }
    

}
